<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use DB;

class PatientCase extends Model
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'patient_case';

     /**
	  * The primary key used by the model.	
	  *	
	  *@var string
      */
    protected $primaryKey = 'id';

    /**
     * Each patient case must have a check doctor, this is the many end of 
     * the one to many relationship
     * 
     * @return user instance;
     */
    public function user()
    {
        return $this->belongsTo('App\User');
    }

    /**
     * Each case has a one to one relationship with a specific patient
     * 
     * @return patient info instance
     */
    public function patient()
    {
        return $this->belongsTo('App\PatientInfo');
    }

    /**
     * Each case can have multiple pictures
     * 
     * @return case related pictures
     */
    public function picture()
    {
        return $this->hasMany('App\PictureInfo','id','case_id');
    }

    /**
     *  Each case can have multiple videos
     * 
     * @return case related video
     */
    public function video()
    {
        return $this->hasMany('App\VideoInfo','id','case_id');
    }
    
	/**
	 * 
	 */
	public static function findCaseByKeyword($keyword)
	{
		$caselist = DB::table('patient_case')->where('first_name','like',"%$keyword%")
		->orWhere('last_name','like',"%$keyword%")
		->orWhere('description','like',"%$keyword%")->distinct()->paginate(5);	
					
		return $caselist;
	} 
	

}
